/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package startupcompanymanager2012;

import javax.swing.JOptionPane;

/**
 *
 * @author Matthäus
 */
public class projectCalendar {

    private static int year, month, day;
    private final static int MAX_MONTHS = 12, MAX_DAYS = 30;

    //sets up a type of calendar with year, month, and day
    public projectCalendar() {

        year = 1;
        month = 1;
        day = 1;

    }
    //adds a day

    public static void addDays(int days) {

        day += days;
        correctDate();

    }
    //adds a month

    public static void addMonths(int months) {

        month += months;
        correctDate();
    }
    //adds a year

    public static void addYears(int years) {
        year += years;
        correctDate();

    }
    //corrects the date if needed and pays salary at end of month

    public static void correctDate() {

        if (day > MAX_DAYS) {
            //if days are more then 30, 1 is added to month and the remainder is set as days
            int rest = day % MAX_DAYS;
            month += 1;
            double totalSalary = 0;
            System.out.println("" + Core.devs.size());
            if (Core.devs.size() > 1) {
                //if you have more then one dev in your team you pay their salary
                for (int i = 0; i <= Core.devs.size(); i++) {
                    totalSalary += Core.devs.get(i).calculateSalary();

                }
                if ((Core.capital - totalSalary) < 0) {
                    //you lose the game if you cant pay the salary
                    Core.capital -= totalSalary;
                    JOptionPane.showMessageDialog(null, "You are not able to pay the monthly salary! Game Over!");
                    Core.GameOver();

                } else {
                    Core.capital -= totalSalary;
                    //pay the salary for all devs besides you
                    StartupCompanyManager2012View.liveBudget.setText(Core.nfmt.format(Core.capital));
                    JOptionPane.showMessageDialog(null, "You just paid " + Core.nfmt.format(Core.capital) + " as salary for your employee/s!");
                }
            }
            for (int i = 0; i < Core.games.size(); i++) {
//TOCHANGE: basic gameIncome calculator, gives an income relative to the score
                if (Core.games.get(i).getOnTheMarket() < 6) {
                    double gameIncome = 2 * (Core.games.get(i).getScore() / 10.00);
                    Core.capital += gameIncome;
                    StartupCompanyManager2012View.liveBudget.setText(Core.nfmt.format(Core.capital));
                }

            }
            day = rest;
        }
        if (month > MAX_MONTHS) {
            //same as with days, when months reach 12, 1 is added to years and the rest is set as monts
            int rest = month % MAX_MONTHS;
            year += 1;
            month = rest;
        }



    }

    public String toString() {

        String date = "Y: " + year + " M: " + month + " D: " + day;
        return date;

    }
}
